package com.lvnnet.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class PayPageGoto 支付扫码识别
 */
@WebServlet("/payPageGoto.do")
public class PayPageGoto extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PayPageGoto() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.获取扫描工具信息"user-agent"
		String userAgent = request.getHeader("user-agent");
		//2.识别信息工具信息
		if(null != userAgent && !"".equals(userAgent) && userAgent.indexOf("BaiduWallet") > -1)
		{
			//user-agent：Mozilla/5.0 (Linux; Android 7.0; EVA-AL10 Build/HUAWEIEVA-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36 BaiduWallet-6.6.0.8-Android-walletapp_1080_1794_EVA-AL10-HWEVA_24_7.0_2.9.5_295
			request.setAttribute("toolname", "百度钱包");
		}
		else if(null != userAgent && !"".equals(userAgent) && userAgent.indexOf("MicroMessenger") > -1)
		{
			//user-agent：Mozilla/5.0 (Linux; Android 7.0; EVA-AL10 Build/HUAWEIEVA-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043220 Safari/537.36 MicroMessenger/6.5.7.1041 NetType/WIFI Language/zh_CN
			request.setAttribute("toolname", "微信");
		}
		else if(null != userAgent && !"".equals(userAgent) && userAgent.indexOf("AlipayClient") > -1)
		{
			//user-agent：Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; EVA-AL10 Build/HUAWEIEVA-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.3.8.909 UCBS/2.10.1.4 Mobile Safari/537.36 Nebula AlipayDefined(nt:WIFI,ws:360|0|3.0) AliApp(AP/10.0.12.042101) AlipayClient/10.0.12.042101 Language/zh-Hans useStatusBar/true
			request.setAttribute("toolname", "支付宝");
		}
		else if(null != userAgent && !"".equals(userAgent) && userAgent.indexOf("PA QQ") > -1)
		{
			//Mozilla/5.0 (Linux; Android 7.0; EVA-AL10 Build/HUAWEIEVA-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043220 Safari/537.36 V1_AND_SQ_7.0.0_676_YYB_D PA QQ/7.0.0.3135 NetType/WIFI WebP/0.3.0 Pixel/1080
			request.setAttribute("toolname", "聊天QQ");
		}
		else
		{
			request.setAttribute("toolname", "浏览器直接访问");
		}
		//返回结果页面
		request.setAttribute("useragent", userAgent);
		request.getRequestDispatcher("WEB-INF/view/readSaoToolResul.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
